﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

using Flagwind.Utilities.DataBuilder.Controls;

namespace Flagwind.Utilities.DataBuilder
{
	public partial class FMain : Form, IMasterContainer
	{
		#region 私有字段

	    private Explorer _explorer;

		#endregion

		#region 构造方法

		public FMain()
        {
            InitializeComponent();

			// 初始化资源管理器
			this.InitExplorer();

			// 初始化标题
			this.InitTitle();
		}

		#endregion

		#region 公共方法

		/// <summary>
		/// 打开一个 Panel。
		/// </summary>
		/// <param name="sender">数据发送者。</param>
		/// <param name="panel">面板实例。</param>
		public void OpenPanel(object sender, UserControl panel)
		{
			var tabPage = new TabPage
			{
				Text = panel.Text,
				Name = panel.Name
			};

			tabPage.Controls.Add(panel);
			tabControl.Visible = true;
			tabControl.TabPages.Add(tabPage);
			tabControl.SelectTab(tabPage);
		}

		#endregion

		#region 事件方法

		/// <summary>
		/// 当点击关闭 Tab 选项卡时调用。
		/// </summary>
		/// <param name="sender">事件发送者。</param>
		/// <param name="e">事件参数。</param>
		private void tsmiCloseTab_Click(object sender, EventArgs e)
		{
			tabControl.TabPages.Remove(tabControl.SelectedTab);

			if(tabControl.TabPages.Count == 0)
				tabControl.Visible = false;
		}

		/// <summary>
		/// 当 TabControl 点击右键时调用。
		/// </summary>
		/// <param name="sender">事件发送者。</param>
		/// <param name="e">事件参数。</param>
		private void tabControl_MouseDown(object sender, MouseEventArgs e)
		{
			if((e.Y < this.tabControl.GetTabRect(0).Bottom) && (e.Button == MouseButtons.Right))
			{
				tabContextMenuStrip.Show(this.tabControl, e.X, e.Y);
			}
		}

		/// <summary>
		/// 当点击
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void btnConnect_Click(object sender, EventArgs e)
		{

		}

		#endregion

		#region 私有方法

		/// <summary>
		/// 初始化资源管理器。
		/// </summary>
	    private void InitExplorer()
	    {
			this._explorer = new Explorer(this);
			this._explorer.Dock = DockStyle.Fill;

			// 添加资源管理器
			pnlExplorer.Controls.Add(_explorer);
	    }

		/// <summary>
		/// 初始化窗体标题。
		/// </summary>
	    private void InitTitle()
	    {
			this.Text = string.Format("Flagwind.Data 生成器 {0}", Utility.AppVersion);
	    }

	    #endregion
	}
}
